package com.seeTools.next.controller.member;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seeTools.next.api.entity.member.MemberInfo;
import com.seeTools.next.api.excel.utils.ExcelUtil;
import com.seeTools.next.common.core.PageQuery;
import com.seeTools.next.common.core.Result;
import com.seeTools.next.service.member.MemberInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author seeTools
 * @since 2025-08-27
 */
@Validated
@RestController
@RequestMapping("/member/info")
public class MemberInfoController {

    @Resource
    private MemberInfoService memberInfoService;

    /**
     * 分页查询
     *
     * @param pageQuery
     * @return
     */
    @PostMapping("/list")
    public Result<Page<MemberInfo>> findList(@RequestBody PageQuery<MemberInfo> pageQuery) {
        Page<MemberInfo> pageInfo = memberInfoService.findList(pageQuery);
        return Result.success(pageInfo);

    }

    /**
     * 修改
     *
     * @return
     */
    @PutMapping()
    public Result<Void> edit(@RequestBody MemberInfo memberInfo) {
        return Result.state(memberInfoService.updateOnLock(memberInfo));
    }

    /**
     * 删除
     *
     * @return
     */
    @DeleteMapping()
    public Result<Void> remove(@RequestBody MemberInfo memberInfo) {
        return Result.state(memberInfoService.removeById(memberInfo));
    }

    /**
     * 添加
     *
     * @return
     */
    @PostMapping()
    public Result<Void> add(@RequestBody MemberInfo memberInfo) {
        return Result.state(memberInfoService.save(memberInfo));
    }


    /**
     * 获取详情
     *
     * @return
     */
    @GetMapping("/{id}")
    public Result<MemberInfo> getInfo(@PathVariable("id") Long id) {
        return Result.state(memberInfoService.getById(id));
    }

    /**
     * 查询全部
     *
     * @return
     */
    @PostMapping("/all")
    public Result<List<MemberInfo>> findAll() {
        return Result.state(memberInfoService.findAll());
    }


    /**
     * 导出
     *
     * @param response
     */
    @PostMapping("/export")
    public void excel(HttpServletResponse response, @RequestBody MemberInfo memberInfo) {
        List<MemberInfo> list = memberInfoService.selectDataList(memberInfo);
        ExcelUtil.exportExcel(list, "导出详情", MemberInfo.class, response);
    }
}
